using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;
using Microsoft.Practices.RecipeFramework;
using VSSDKAssist.Assets.Helpers;
using VSSDKAssist.Assets.Actions.Base;
using System.Globalization;

namespace VSSDKAssist.Recipes.CreateVSToolWindow
{
	/// <summary>
	/// Action that adds/update the ProvideToolWindowVisibility attribute
	/// </summary>
	public class AddProvideToolWindowVisibilityAttributeAction : ActionBase
	{
		#region Properties
		private CodeClass codeClass;

		/// <summary>
		/// Gets or sets the code class.
		/// </summary>
		/// <value>The code class.</value>
		[Input(Required = true)]
		public CodeClass CodeClass
		{
			get { return codeClass; }
			set { codeClass = value; }
		}

		private string toolWindowName;

		/// <summary>
		/// Gets or sets the name of the tool window.
		/// </summary>
		/// <value>The name of the tool window.</value>
		[Input(Required = true)]
		public string ToolWindowName
		{
			get { return toolWindowName; }
			set { toolWindowName = value; }
		}

		private string toolWindowNamespace;

		/// <summary>
		/// Gets or sets the tool window namespace.
		/// </summary>
		/// <value>The tool window namespace.</value>
		[Input(Required = true)]
		public string ToolWindowNamespace
		{
			get { return toolWindowNamespace; }
			set { toolWindowNamespace = value; }
		}

		private Guid uiContextGuid;

		/// <summary>
		/// Gets or sets the UI context GUID.
		/// </summary>
		/// <value>The UI context GUID.</value>
		[Input(Required = true)]
		public Guid UIContextGuid
		{
			get { return uiContextGuid; }
			set { uiContextGuid = value; }
		} 
		#endregion

		#region Protected Implementation
		/// <summary>
		/// Called when [execute].
		/// </summary>
		protected override void OnExecute()
		{
			string attName = "ProvideToolWindowVisibility";
			string attValue =
				string.Format(
					CultureInfo.CurrentCulture,
					"typeof({0}.{1}),\"{2}\"",
					this.toolWindowNamespace,
					this.toolWindowName,
					this.uiContextGuid.ToString("B"));

			FileCodeModelHelper.AddAttribute(codeClass, attName, attValue, false);
		} 
		#endregion
	}
}